/*
 * @Author: TJN tjn@246@126.com
 * @Date: 2024-07-16 13:04:48
 * @LastEditors: TJN tjn@246@126.com
 * @LastEditTime: 2024-07-16 17:22:29
 * @FilePath: \router\vite\util.ts
 * @Description:
 *
 * Copyright (c) 2024 by ${git_name_email}, All Rights Reserved.
 */
import _ from "lodash";

// 处理环境变量,因为在env文件里都是字符串,经过处理转换为原始类型  布尔  数值
export function parseEnv(env: Record<string, any>): viteEnv {
  const envs: any = _.cloneDeep(env);

  Object.entries(env).forEach(([key, value]) => {
    if (value == "true" || value == "false")
      envs[key] = value == "true" ? true : false;
    else if (/^\d+$/.test(value)) envs[key] = Number(value);
    else if (value == "null") envs[key] = null;
    else if (value == "undefined") envs[key] = undefined;
  });

  return envs;
}
